﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace CustomConsole
{
    public class ConsoleBuffer
    {
        public CHAR_INFO[] Chars { get; set; }

        public int Columns { get; set; }
        public int Rows { get; set; }

        public bool CharExist(int col, int row)
        {
            if (Chars == null)
                return false;
            return col < Columns && row < Rows;
        }

        public CHAR_INFO Char(int col, int row)
        {
            Debug.Assert(CharExist(col, row));
            return Chars[row * Columns + col];
        }

        public bool MatchChar(int col, int row, CHAR_INFO target)
        {
            if (!CharExist(col, row))
                return false;
            CHAR_INFO cur = Char(col, row);
            return cur.Attributes == target.Attributes && cur.Char.UnicodeChar == target.Char.UnicodeChar;
        }
    }
}
